from PyQt5 import uic

#if you don't know how to update the ui.py file when .ui file changes, add this command 
#which will automatically translate all .ui file in specific directory into corespondent .py file
#
uic.compileUiDir('UI')
#

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QThread
from UI.control_widget import ControlWidget
from window import Window
from simulation import Simulation
from Demo.stvk_bunny import stvkBunny
from driver import Driver


if __name__ == '__main__':
    
    driver = Driver()
    
    app = QApplication(sys.argv)
    control = ControlWidget(driver)
    
    scene_graph = stvkBunny(control)
    print("construct scene graph and bind gui controller successfully! ")
    
    window = Window(scene_graph)
    window.resize(800,600)
    window.move(0,0)
    simulation = Simulation(scene_graph, driver, 0.04)
    
    thread = QThread()
    simulation.moveToThread(thread)
    
    thread.started.connect(simulation.start)
    simulation.update_window.connect(window.updateWindow)
    simulation.finished.connect(window.close)
    simulation.finished.connect(thread.quit)
    
    thread.start()
    
    control.show()
    window.show()
    sys.exit(app.exec())